using System;
namespace Servlets.Api
{
	/// <summary>
	/// Represents the Http Versions that can be sent or recieved.
	/// </summary>
	public class HttpVersion
	{
		public static HttpVersion V1_0 = new HttpVersion("HTTP/1.0");
		public static HttpVersion V1_1 = new HttpVersion("HTTP/1.1");
		
		public string Value{get;private set;}
		private HttpVersion(string value)
		{
			this.Value = value;
		}
		
		/// <summary>
		/// Parses the Http version from the string. If the version is not present, an InvalidHttpVersionStringException will be thrown
		/// </summary>
		/// <param name="version">
		/// A <see cref="System.String"/>
		/// </param>
		/// <returns>
		/// A <see cref="HttpVersion"/>
		/// </returns>
		public static HttpVersion ParseHttpVersion(string version) {
			if(version == "HTTP/1.0") {
				return HttpVersion.V1_0;
			}
			if(version == "HTTP/1.1") {
				return HttpVersion.V1_1;
			}
			
			throw new Servlets.Exceptions.InvalidHttpVersionStringException(version);
		}
		
		public override string ToString ()
		{
			return Value;
		}
	}
}

